package com.viphuli.fragment;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import com.loopj.android.http.RequestParams;
import com.offroader.utils.DateUtils;
import com.offroader.utils.LogUtils;
import com.offroader.utils.StringUtils;
import com.offroader.utils.ViewUtils;
import com.viphuli.activity.LocationActivity;
import com.viphuli.app.R;
import com.viphuli.common.AccessTokenKeeper;
import com.viphuli.common.Constants;
import com.viphuli.common.MyPageHelper;
import com.viphuli.http.ApiRequest;
import com.viphuli.http.handler.MyBaseHttpResponseHandler.HandlerType;

/**
 * 提交订单
 * 
 * @author li.li
 *
 */
public class PurchaseOrderFillFragment extends BaseProgressFragment implements OnClickListener, TextWatcher {

	@Bind(R.id.id_main_content_service_company_order_name)
	protected TextView orderName;

	@Bind(R.id.id_main_content_service_company_order_people_num_text)
	protected EditText orderPeopleNumText;

	@Bind(R.id.id_main_content_service_company_order_time)
	protected TextView orderTime;

	@Bind(R.id.id_main_content_service_company_order_site)
	protected TextView orderSite;

	@Bind(R.id.id_main_content_service_company_order_better_site)
	protected EditText orderBetterSite;

	@Bind(R.id.id_main_content_service_company_order_contact)
	protected EditText orderContacts;

	@Bind(R.id.id_main_content_service_company_order_phone)
	protected EditText orderPhone;

	@Bind(R.id.id_main_content_service_company_order_mail_layout)
	protected ViewGroup orderEMailLayout;

	@Bind(R.id.id_main_content_service_company_order_mail)
	protected EditText orderEMail;

	@Bind(R.id.id_main_content_service_company_order_remark)
	protected EditText orderRemark;

	@Bind(R.id.id_main_content_service_company_order_people_num_add)
	protected TextView orderPeopleNumAdd;

	@Bind(R.id.id_main_content_service_company_order_people_num_decrease)
	protected TextView orderPeopleNumDecrease;

	@Bind(R.id.id_main_content_service_company_order_btn)
	protected TextView orderBtn;

	private int serviceType;
	private int serviceItemId;
	private String serviceItemName;
	private String orderId;
	private Date selectDate = new Date();
	private ViewGroup selectDateLayout;
	private TextView selectTimeText;

	@Override
	protected int obtainContentRes() {
		return R.layout.frag_order_fill;
	}

	@Override
	protected void initParams() {

		Bundle args = getArguments();
		serviceType = args.getInt("service_type");
		serviceItemId = args.getInt("service_item_id");
		serviceItemName = args.getString("service_item_name");

		/** 当orderId不为空时，从网络加载定单信息，自动填充 */
		orderId = args.getString("order_id");

	}

	@Override
	protected void initView() {
		//		caller.getRightBtn().setVisibility(View.VISIBLE);
		//		caller.getRightText().setText(getString(R.string.str_main_home_service_item_info_introduce));
		//		caller.getRightBtn().setOnClickListener(this);
		orderName.setText(serviceItemName);

		//控制邮箱显示（企业预约服务显示邮箱，个人预约不显示）
		if (Constants.HOME_SERVICE_HEALTH_COMPANY == serviceType) {
			orderEMailLayout.setVisibility(View.VISIBLE);//企业体检
			orderPeopleNumText.setText(String.valueOf(Constants.ORDER_MIN_NUMBER_COMPANY));
		} else {
			orderEMailLayout.setVisibility(View.GONE);
			orderPeopleNumText.setText(String.valueOf(Constants.ORDER_MIN_NUMBER_PERSON));
		}

		orderContacts.addTextChangedListener(this);//联系人
		orderPhone.addTextChangedListener(this);//电话
		orderTime.addTextChangedListener(this);//时间
		orderSite.addTextChangedListener(this);//地址
		orderRemark.addTextChangedListener(this);//备注
		orderPeopleNumText.addTextChangedListener(this);//数量
		orderEMail.addTextChangedListener(this);//邮箱
		orderBtn.addTextChangedListener(this);//提交订单

		verifyFiled();

	}

	@Override
	protected void initData() {

		if (StringUtils.isNotBlank(orderId)) {
			/**
			 * 【自动填充表单】当定单ID不为空时，读取订单信息，填充（再次预订 ）
			 */
			RequestParams params = new RequestParams();
			params.put("order_id", orderId);
			ApiRequest.purchaseAutoFillReOrder.request(this, params);

		} else {

			AccessTokenKeeper tokenKeeper = AccessTokenKeeper.readAccessToken(getActivity());
			if (tokenKeeper.isLogin()) {

				RequestParams params = new RequestParams();

				/**
				 * 【自动填充表单】当用户信息不为空，且有手机号，填充（新用户）
				 */
				params.put("uid", tokenKeeper.getOpenId());
				ApiRequest.purchaseAutoFillPhone.request(this, params, HandlerType.waitting, false);

				/**
				 * 【自动填充表单】当用户已订购，获得最近订单，填充（已订购用户）
				 */
				params.put("uid", tokenKeeper.getOpenId());
				params.put("page", 1);
				ApiRequest.purchaseAutoFillAlreadyOrder.request(this, params, HandlerType.waitting, false);

			}
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getActivity().getMenuInflater().inflate(R.menu.menu_order_fill, menu);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		if (R.id.id_menu_menu_order_fill_right == item.getItemId()) {

			RequestParams params = new RequestParams();
			params.put("service_item_id", serviceItemId);

			ApiRequest.purchaseInstructions.request(getActivity(), params);
			return true;
		}

		return false;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.id_common_bar_right_btn:

			ApiRequest.purchaseInstructions.request(getActivity());

			break;

		default:
			break;
		}

	}

	@OnClick(R.id.id_main_content_service_company_order_people_num_add)
	public void peopleNumAdd() {

		String numStr = orderPeopleNumText.getText().toString();

		int num = Integer.valueOf(numStr);
		orderPeopleNumText.setText(String.valueOf(++num));

	}

	@OnClick(R.id.id_main_content_service_company_order_people_num_decrease)
	public void peopleNumDecrease() {

		String numStr = orderPeopleNumText.getText().toString();

		if (StringUtils.isNotBlank(numStr) && !"0".equals(numStr)) {

			int num = Integer.valueOf(numStr);
			orderPeopleNumText.setText(String.valueOf(--num));

		}
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count, int after) {
	}

	@Override
	public void afterTextChanged(Editable s) {

		verifyNum();
		verifyFiled();
	}

	/**
	 * 验证订购数
	 */
	private void verifyNum() {
		String number = orderPeopleNumText.getText().toString();

		if (StringUtils.isBlank(number) || Integer.parseInt(number) <= Constants.ORDER_MIN_NUMBER_PERSON) {//下限

			orderPeopleNumDecrease.setBackgroundResource(R.drawable.bg_decrease_number_disable);

			if (StringUtils.isBlank(number) || Integer.parseInt(number) < Constants.ORDER_MIN_NUMBER_PERSON)
				orderPeopleNumText.setText(String.valueOf(Constants.ORDER_MIN_NUMBER_PERSON));

		} else if (Integer.parseInt(number) >= Constants.ORDER_MAX_NUMBER) {//上限

			orderPeopleNumAdd.setBackgroundResource(R.drawable.bg_add_number_disabled);

			if (Integer.parseInt(number) > Constants.ORDER_MAX_NUMBER)
				orderPeopleNumText.setText(String.valueOf(Constants.ORDER_MAX_NUMBER));

		} else {//可点击

			orderPeopleNumDecrease.setBackgroundResource(R.drawable.sl_decrease_number);
			orderPeopleNumAdd.setBackgroundResource(R.drawable.sl_add_number);

		}
	}

	/**
	 * 动态验证表单
	 */
	private void verifyFiled() {

		String contact = orderContacts.getText().toString();
		String tel = orderPhone.getText().toString();
		String number = orderPeopleNumText.getText().toString();
		String serviceTime = orderTime.getText().toString();
		String site = orderSite.getText().toString();
		String betterSite = orderBetterSite.getText().toString();
		String mail = orderEMail.getText().toString();

		if (StringUtils.isBlank(tel) //
				|| StringUtils.isBlank(contact) //
				|| StringUtils.isBlank(mail)
				&& (Constants.HOME_SERVICE_HEALTH_COMPANY == serviceType) //邮箱
				|| StringUtils.isBlank(serviceTime) //
				|| StringUtils.isBlank(site)//
				|| (StringUtils.isBlank(number) || Integer.parseInt(number) < Constants.ORDER_MIN_NUMBER_PERSON)
				&& (Constants.HOME_SERVICE_NURSE_PERSON == serviceType || Constants.HOME_SERVICE_HEALTH_PERSON == serviceType || Constants.HOME_SERVICE_CONSULT == serviceType) //个人订单
				|| (StringUtils.isBlank(number) || Integer.parseInt(number) < Constants.ORDER_MIN_NUMBER_COMPANY)
				&& (Constants.HOME_SERVICE_HEALTH_COMPANY == serviceType)//企业订单
				|| StringUtils.isBlank(betterSite)) {

			orderBtn.setBackgroundResource(R.drawable.bg_common_btn_blue_pressed);

		} else {
			orderBtn.setBackgroundResource(R.drawable.sl_common_btn_blue);
		}

	}

	@OnClick(R.id.id_main_content_service_company_order_time)
	public void showDateTimeDialog() {

		Dialog dialog = ViewUtils.customBottomAnim(getActivity(), R.layout.dialog_order_datatime_picker);

		//初始化日期
		initDialogDate(dialog);

		dialog.show();
	}

	private void initDialogDate(final Dialog dialog) {

		//项端日期
		ViewGroup oneDayLayout = ButterKnife.findById(dialog, R.id.id_order_datatime_day_one_layout);
		ViewGroup twoDayLayout = ButterKnife.findById(dialog, R.id.id_order_datatime_day_two_layout);
		ViewGroup threeDayLayout = ButterKnife.findById(dialog, R.id.id_order_datatime_day_three_layout);
		ViewGroup fourDayLayout = ButterKnife.findById(dialog, R.id.id_order_datatime_day_four_layout);
		ViewGroup fiveDayLayout = ButterKnife.findById(dialog, R.id.id_order_datatime_day_five_layout);

		final List<ViewGroup> daysLayouts = Arrays.asList(oneDayLayout, twoDayLayout, threeDayLayout, fourDayLayout, fiveDayLayout);

		//初始化
		selectDateLayout = oneDayLayout;
		selectDate = new Date();

		Date date = selectDate;//当前日期
		for (int i = 0; i < daysLayouts.size(); i++) {
			//赋值
			final TextView weekDay = ButterKnife.findById(daysLayouts.get(i), R.id.id_order_datatime_day_weekday);
			final TextView day = ButterKnife.findById(daysLayouts.get(i), R.id.id_order_datatime_day_date);

			if (DateUtils.isSameDay(date, new Date())) {
				weekDay.setText("今天");
			} else {
				weekDay.setText(DateUtils.getWeekOfDate(date));
			}

			day.setText(DateUtils.formatMonthDay(date));

			final ViewGroup dayLayout = daysLayouts.get(i);
			final Date tempDate = date;

			dayLayout.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View view) {

					if (selectDateLayout != null) {
						selectDateLayout.setBackgroundResource(R.color.bg_common_white);
						TextView weekDay = ButterKnife.findById(selectDateLayout, R.id.id_order_datatime_day_weekday);
						TextView day = ButterKnife.findById(selectDateLayout, R.id.id_order_datatime_day_date);
						weekDay.setTextColor(getResources().getColor(R.color.cl_common_text_hint_2));
						day.setTextColor(getResources().getColor(R.color.cl_common_text_hint_2));
					}

					dayLayout.setBackgroundResource(R.color.bg_common_top_title);
					weekDay.setTextColor(getResources().getColor(R.color.bg_common_white));
					day.setTextColor(getResources().getColor(R.color.bg_common_white));

					selectDateLayout = dayLayout;
					selectDate = tempDate;

					//选择日期后刷新时间
					initDialogTime(dialog);
				}
			});

			//日期加1
			date = DateUtils.addDay(date, 1);

			initDialogTime(dialog);
		}

	}

	private void initDialogTime(final Dialog dialog) {
		//底部时间
		TextView time1 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_1);
		TextView time2 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_2);
		TextView time3 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_3);
		TextView time4 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_4);
		TextView time5 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_5);
		TextView time6 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_6);
		TextView time7 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_7);
		TextView time8 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_8);
		TextView time9 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_9);
		TextView time10 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_10);
		TextView time11 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_11);
		TextView time12 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_12);
		TextView time13 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_13);
		TextView time14 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_14);
		TextView time15 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_15);
		TextView time16 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_16);
		TextView time17 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_17);
		TextView time18 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_18);
		TextView time19 = ButterKnife.findById(dialog, R.id.id_order_datatime_time_19);

		List<TextView> times = Arrays.asList(time1,//
				time2,//
				time3, //
				time4, //
				time5, //
				time6, //
				time7, //
				time8, //
				time9, //
				time10, //
				time11, //
				time12, //
				time13, //
				time14, //
				time15, //
				time16, //
				time17, //
				time18, //
				time19);
		
		Calendar validTimeCal = Calendar.getInstance();
		validTimeCal.setTime(new Date());//当前时间
		validTimeCal.add(Calendar.HOUR_OF_DAY, 3);//延时3小时

		boolean isSameDay = DateUtils.isSameDay(validTimeCal.getTime(), selectDate);
		if (isSameDay) {

			//从当前日期的九点开始
			Calendar cal = Calendar.getInstance();
			cal.setTime(selectDate);
			cal.set(Calendar.HOUR_OF_DAY, 9);
			cal.set(Calendar.MINUTE, 0);
			cal.set(Calendar.SECOND, 0);
			cal.set(Calendar.MILLISECOND, 0);

			int i = 0;
			for (TextView timeText : times) {

				//从当前日期的九点开始,设置时间
				Date curDateTime = DateUtils.addMinite(cal.getTime(), i);
				i += 30;
				timeText.setText(DateUtils.formatHM(curDateTime));
				timeText.setTag(curDateTime);

				String timeStr = timeText.getText().toString();

				long time = DateUtils.getHmTime(timeStr);
				String valideTimeStr = DateUtils.formatHM(validTimeCal.getTime());
				long valideTime = DateUtils.getHmTime(valideTimeStr);

				if (time <= valideTime) {//选择的时间小于当前的时间时不可选

					timeText.setBackgroundResource(R.drawable.bg_solid_corner_gray);
					timeText.setTextColor(getResources().getColor(R.color.cl_common_line_gray));

					timeText.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View view) {
							ViewUtils.toast(getString(R.string.tip_address_can_not_choose));
						}
					});

				} else {

					timeText.setBackgroundResource(R.drawable.sl_common_btn_green_line);
					timeText.setTextColor(getResources().getColor(R.color.cl_common_text_green));

					timeText.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View view) {
							TextView tv = (TextView) view;

							if (selectTimeText != null) {
								selectTimeText.setBackgroundResource(R.drawable.sl_common_btn_green_line);
								selectTimeText.setTextColor(getResources().getColor(R.color.cl_common_text_green));
							}

							tv.setBackgroundResource(R.drawable.sl_common_btn_blue_line);
							tv.setTextColor(getResources().getColor(R.color.cl_common_text_blue));
							selectTimeText = tv;
						}
					});

				}

			}

		} else {

			//从当前日期的九点开始
			Calendar cal = Calendar.getInstance();
			cal.setTime(selectDate);
			cal.set(Calendar.HOUR_OF_DAY, 9);
			cal.set(Calendar.MINUTE, 0);
			cal.set(Calendar.SECOND, 0);
			cal.set(Calendar.MILLISECOND, 0);

			int i = 0;
			for (TextView timeText : times) {

				//从当前日期的九点开始,设置时间
				Date curDateTime = DateUtils.addMinite(cal.getTime(), i);
				i += 30;
				timeText.setText(DateUtils.formatHM(curDateTime));
				timeText.setTag(curDateTime);

				timeText.setBackgroundResource(R.drawable.sl_common_btn_green_line);
				timeText.setTextColor(getResources().getColor(R.color.cl_common_text_green));

				timeText.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View view) {
						TextView tv = (TextView) view;

						if (selectTimeText != null) {
							selectTimeText.setBackgroundResource(R.drawable.sl_common_btn_green_line);
							selectTimeText.setTextColor(getResources().getColor(R.color.cl_common_text_green));
						}

						tv.setBackgroundResource(R.drawable.sl_common_btn_blue_line);
						tv.setTextColor(getResources().getColor(R.color.cl_common_text_blue));
						selectTimeText = tv;
					}
				});
			}

		}

		TextView submitBtn = ButterKnife.findById(dialog, R.id.id_order_datatime_ensure);

		submitBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View view) {

				TextView dataText = ButterKnife.findById(selectDateLayout, R.id.id_order_datatime_day_date);
				if (StringUtils.isBlank(dataText.getText().toString())) {
					ViewUtils.toast(R.string.tip_datetime_date);
					return;
				}
				if (selectTimeText == null || StringUtils.isBlank(selectTimeText.getText().toString())) {
					ViewUtils.toast(R.string.tip_datetime_time);
					return;
				}

				//							ViewUtils.toast("提交|" + selectTimeText.getText() + "|" + dataText.getText());
				selectDate = (Date) selectTimeText.getTag();
				String time = DateUtils.format(selectDate);
				orderTime.setText(time);
				dialog.dismiss();
			}
		});
	}

	@OnClick(R.id.id_main_content_service_company_order_site)
	public void location() {
		Intent intent = new Intent(getActivity(), LocationActivity.class);
		startActivityForResult(intent, Constants.ACTIVITY_REQUEST_MAP_CODE);
	}

	@OnClick(R.id.id_main_content_service_company_order_btn)
	public void submit() {

		String contact = orderContacts.getText().toString();
		String tel = orderPhone.getText().toString();
		String number = orderPeopleNumText.getText().toString();
		String serviceTime = orderTime.getText().toString();
		String site = orderSite.getText().toString();
		String betterSite = orderBetterSite.getText().toString();
		String remark = orderRemark.getText().toString();
		String mail = orderEMail.getText().toString();

		if (StringUtils.isBlank(tel)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_contact), Toast.LENGTH_SHORT).show();
			return;
		}
		if (StringUtils.isBlank(contact)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_phone_number), Toast.LENGTH_SHORT).show();
			return;
		}
		if (StringUtils.isBlank(number) || Integer.parseInt(number) < Constants.ORDER_MIN_NUMBER_PERSON) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_number_person + Constants.ORDER_MIN_NUMBER_PERSON), Toast.LENGTH_SHORT).show();
			return;
		}
		if (Constants.HOME_SERVICE_HEALTH_COMPANY == serviceType
				&& (StringUtils.isBlank(number) || Integer.parseInt(number) < Constants.ORDER_MIN_NUMBER_COMPANY)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_number_company) + Constants.ORDER_MIN_NUMBER_COMPANY, Toast.LENGTH_SHORT)
					.show();
			return;
		}
		if (StringUtils.isBlank(serviceTime)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_service_time), Toast.LENGTH_SHORT).show();
			return;
		}
		if (StringUtils.isBlank(site)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_site), Toast.LENGTH_SHORT).show();
			return;
		}
		if (StringUtils.isBlank(betterSite)) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_better_site), Toast.LENGTH_SHORT).show();
			return;
		}
		if (StringUtils.isBlank(mail) && Constants.HOME_SERVICE_HEALTH_COMPANY == serviceType) {
			Toast.makeText(getActivity(), getString(R.string.tip_input_mail), Toast.LENGTH_SHORT).show();
			return;
		}

		AccessTokenKeeper token = AccessTokenKeeper.readAccessToken(getActivity());

		if (token.isLogin()) {

			try {

				RequestParams params = new RequestParams();
				params.put("service_item_id", serviceItemId);//商品ID
				params.put("service_time", selectDate.getTime());
				params.put("count", number);
				params.put("address", site);
				params.put("better_address", betterSite);
				params.put("person_contact", contact);
				params.put("tel", tel);
				params.put("service_type", serviceType);

				if (StringUtils.isBlank(remark))
					params.put("remark", "");
				else
					params.put("remark", remark);

				params.put("email", mail);
				params.put("uid", token.getOpenId());

				ApiRequest.purchaseOrderFill.request(this, params);

			} catch (Throwable e) {
				LogUtils.error(e.getMessage(), e);
			}

		} else {
			AccountLoginFragment.goWithConfirm(getActivity());
		}

	}

	public TextView getOrderName() {
		return orderName;
	}

	public TextView getOrderSite() {
		return orderSite;
	}

	public EditText getOrderBetterSite() {
		return orderBetterSite;
	}

	public EditText getOrderContacts() {
		return orderContacts;
	}

	public EditText getOrderPhone() {
		return orderPhone;
	}
	
	public ViewGroup getOrderEMailLayout() {
		return orderEMailLayout;
	}

	public EditText getOrderPeopleNumText() {
		return orderPeopleNumText;
	}

	public String getOrdeId() {
		return orderId;
	}

	public void setServiceType(int serviceType) {
		this.serviceType = serviceType;
	}

	public void setServiceItemId(int serviceItemId) {
		this.serviceItemId = serviceItemId;
	}

	public static void go(Activity act, int serviceItemId, int serviceType, String serviceItemName) {

		AccessTokenKeeper token = AccessTokenKeeper.readAccessToken(act);

		if (token.isLogin()) {

			Bundle args = new Bundle();
			args.putInt("service_type", serviceType);
			args.putInt("service_item_id", serviceItemId);
			args.putString("service_item_name", serviceItemName);
			MyPageHelper.purchaseOrderFill.showMyPage(act, args);

		} else {
			AccountLoginFragment.goWithConfirm(act);
		}

	}

	public static void go(Activity act, String orderId) {

		Bundle args = new Bundle();
		args.putString("order_id", orderId);
		MyPageHelper.purchaseOrderFill.showMyPage(act, args);

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == Activity.RESULT_OK) {

			if (requestCode == Constants.ACTIVITY_REQUEST_MAP_CODE) {

				String locationName = null;
				String adress = null;

				if (data != null || StringUtils.isBlank(adress)) {
					locationName = data.getStringExtra(LocationActivity.KEY_SELECTED_LOCAL_NAME);
					adress = data.getStringExtra(LocationActivity.KEY_SELECTED_ADDRESS);
					orderSite.setText(locationName);
				} else {
					ViewUtils.toast(R.string.tip_address_get_fails);
				}

			}

		}

	}

}
